/*
 * 用户表数据存取对像
 */
package com.floatpoint.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import com.floatpoint.db.DbConnManager;
import com.floatpoint.model.User;

public class UserDAO {
	public boolean isLogin(User user) {		
		boolean ret = false;
		
		Connection conn = DbConnManager.getConnection();
		
		String sql = "select * from user where username=? and password=?";
		PreparedStatement pstm = null;
		try {
			pstm = conn.prepareStatement(sql);
			pstm.setString(1, user.getUsername());
			pstm.setString(2, user.getPassword());
			
			ResultSet rs = pstm.executeQuery();
			if (rs.next()) {
				ret = true;
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
		
		if (pstm != null) {
			try {
				pstm.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}

		if (conn != null) {
			try {
				conn.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		
		return ret;
	}
	
	public static void main(String[] args) {
		UserDAO userDAO = new UserDAO();
		User user = new User();
		user.setUsername("admin");
		user.setPassword("1243");
		boolean r = userDAO.isLogin(user);
		System.out.println(r);
	}
}
